package com.jsle.common.artifactory;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jsle.financial.domain.User;

public class DefaultFilter implements Filter{

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest httpRequest = null;
		User user = null;
		if(request instanceof HttpServletRequest){
			httpRequest = (HttpServletRequest)request;
			user = (User)httpRequest.getSession().getAttribute("user");
		}
		String url = httpRequest.getRequestURI();
		if((url.endsWith("/valideUserInfo.do"))||(user!=null)||(url.endsWith("/login.jsp"))){
			chain.doFilter(request, response);
		}else{
			((HttpServletResponse)response).sendRedirect(httpRequest.getContextPath()+"/login.jsp");
			return;
		}
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
